<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="msapplication-config" content="browserconfig.xml" />
    <title>Using the Terraform OpenStack Provider</title>
    <link rel="apple-touch-icon" sizes="180x180" href="/kitchen-terraform/apple-touch-icon-180x180-precomposed.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/kitchen-terraform/apple-touch-icon-152x152-precomposed.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/kitchen-terraform/apple-touch-icon-144x144-precomposed.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/kitchen-terraform/apple-touch-icon-114x114-precomposed.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/kitchen-terraform/apple-touch-icon-72x72-precomposed.png">
    <link rel="apple-touch-icon" href="/kitchen-terraform/apple-touch-icon-precomposed.png">
    <link rel="icon" type="image/png" sizes="196x196" href="/kitchen-terraform/favicon-196x196.png">
    <link rel="icon" type="image/png" sizes="160x160" href="/kitchen-terraform/favicon-160x160.png">
    <link rel="icon" type="image/png" sizes="96x96" href="/kitchen-terraform/favicon-96x96.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/kitchen-terraform/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/kitchen-terraform/favicon-16x16.png">
    <link rel="shortcut icon" href="/kitchen-terraform/favicon.png">
    <link rel="icon" type="image/ico" href="/kitchen-terraform/favicon.ico">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
    <link href="/kitchen-terraform/stylesheets/highlighting.css" rel="stylesheet" />
    <link href="/kitchen-terraform/stylesheets/material.css" rel="stylesheet" />
    <link href="/kitchen-terraform/stylesheets/site.css" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
    <script src="/kitchen-terraform/javascripts/site.js"></script>
  </head>
  <body>
    <nav class="navbar fixed-top navbar-expand-lg navbar-light header">
      <img src="/kitchen-terraform/images/kitchen_terraform_logo.png" class="d-inline-block" style="vertical-align: sub; margin-left: 10px;" width="18" height="18" alt="Kitchen-Terraform logo" />
      <a href="/kitchen-terraform/" class="navbar-brand" style="padding-left: 5px;">Kitchen-Terraform</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a href="/kitchen-terraform/getting_started.html" class="nav-link">Getting Started</a>
          </li>
          <li class="nav-item">
            <a href="/kitchen-terraform/tutorials/" class="nav-link">Tutorials</a>
          </li>
          <li class="nav-item">
            <a href="/kitchen-terraform/about.html" class="nav-link">About</a>
          </li>
          <li class="nav-item">
            <a href="/kitchen-terraform/community/" class="nav-link">Community</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="https://github.com/newcontext-oss/kitchen-terraform">
              <img src="/kitchen-terraform/images/github.png" class="d-inline-block" style="vertical-align: sub;" width="18" height="18" alt="GitHub logo" /> Contribute
            </a>
          </li>
        </ul>
      </div>
    </nav>
    <div class="content text-left">
      <div class="container" style="padding-top: 0px;">
  <div class="row">
    <div class="col-12">
      <div class="jumbotron">
        <h1 class="display-3">
          Terraform OpenStack Provider
        </h1>
        <p class="lead">
          This is an example of how to utilize Kitchen-Terraform to test OpenStack resources configured with the <a href="https://www.terraform.io/docs/providers/openstack/index.html" style="color: #32c850;">Terraform OpenStack Provider</a>.
        </p>
        <div class="float-right">Author: Ewa Czechowska</div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-4">
      <div class="list-group" id="list-tab" role="tablist">
        <a class="list-group-item list-group-item-action active" id="list-one-list" data-toggle="list" href="#list-one" role="tab" aria-controls="one">
          1. Requirements & Setup
        </a>
        <a class="list-group-item list-group-item-action" id="list-two-list" data-toggle="list" href="#list-two" role="tab" aria-controls="two">
          2. Create Terraform code
        </a>
        <a class="list-group-item list-group-item-action" id="list-three-list" data-toggle="list" href="#list-three" role="tab" aria-controls="three">
          3. Create Terraform variables
        </a>
        <a class="list-group-item list-group-item-action" id="list-four-list" data-toggle="list" href="#list-four" role="tab" aria-controls="four">
          4. Create Terraform outputs
        </a>
        <a class="list-group-item list-group-item-action" id="list-five-list" data-toggle="list" href="#list-five" role="tab" aria-controls="five">
          5. Setup provider information
        </a>
        <a class="list-group-item list-group-item-action" id="list-six-list" data-toggle="list" href="#list-six" role="tab" aria-controls="six">
          6. Create tests
        </a>
        <a class="list-group-item list-group-item-action" id="list-seven-list" data-toggle="list" href="#list-seven" role="tab" aria-controls="seven">
          7. Run tests
        </a>
      </div>
    </div>
    <div class="col-8">
      <div class="tab-content" id="nav-tabContent">
        <div class="tab-pane fade show active" id="list-one" role="tabpanel" aria-labelledby="list-one-list">
          We need two OpenStack networks that are accessible from localhost.
          <br><hr>
          To setup the repository, run these commands:
          <br><br>
<div class="highlight"><pre class="syntax-highlight shell"><code><span class="nb">mkdir</span> <span class="nt">-p</span> openstack_provider_example/test/integration/example/controls
<span class="nb">mkdir</span> <span class="nt">-p</span> openstack_provider_example/dummy_keypair

ssh-keygen <span class="nt">-f</span> openstack_provider_example/dummy_keypair/cloud.key

<span class="nb">cd </span>openstack_provider_example
</code></pre></div>          Create the <p class="font-weight-bold" style="color: #32c850; display: inline;">Gemfile</p> to install our dependencies.
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">source</span> <span class="s2">"https://rubygems.org/"</span> <span class="k">do</span>
  <span class="n">gem</span> <span class="s2">"kitchen-terraform"</span>
<span class="k">end</span>
</code></pre></div>          Install Kitchen-Terraform and other rubygems, install bundler if not installed yet.
          <br><br>
<div class="highlight"><pre class="syntax-highlight shell"><code>gem <span class="nb">install </span>bundler
bundle <span class="nb">install</span>
</code></pre></div>          Create this file <p class="font-weight-bold" style="color: #32c850; display: inline;">.kitchen.yml</p> which brings together the Terraform module code and Inspec controls.
          <br><br>
          <div class="row">
            <div class="col">
<div class="highlight"><pre class="syntax-highlight yaml"><code><span class="nn">---</span>
<span class="na">driver</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">terraform</span>
  <span class="na">command_timeout</span><span class="pi">:</span> <span class="m">1000</span>
  <span class="na">variable_files</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">./my-variables.tfvars</span>

<span class="na">provisioner</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">terraform</span>

<span class="na">transport</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">ssh</span>
  <span class="na">ssh_key</span><span class="pi">:</span> <span class="s">./dummy_keypair/cloud.key</span>
  <span class="na">username</span><span class="pi">:</span> <span class="s">ubuntu</span>

<span class="na">verifier</span><span class="pi">:</span>
  <span class="na">name</span><span class="pi">:</span> <span class="s">terraform</span>
  <span class="na">groups</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">master</span>
      <span class="na">controls</span><span class="pi">:</span>
        <span class="pi">-</span> <span class="s">nano_installed</span>
      <span class="na">hostnames</span><span class="pi">:</span> <span class="s">master_address</span>
    <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">workers</span>
      <span class="na">controls</span><span class="pi">:</span>
        <span class="pi">-</span> <span class="s">curl_installed</span>
      <span class="na">hostnames</span><span class="pi">:</span> <span class="s">workers_addresses</span>

<span class="na">platforms</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">ubuntu</span>

<span class="na">suites</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">example</span>


</code></pre></div>            </div>
            <div class="col">
              <br><br>
              The Kitchen-Terraform driver is configured with a command timeout of 1000 seconds and the path to a Terraform variables file.
              <br><br><br>
              The Kitchen-Terraform provisioner is enabled.
              <br><br><br>
              The Test Kitchen SSH transport is configured to use the dummy_keypair and a static username for SSH authentication with the VMs.
              <br><br>
              The Kitchen-Terraform verifier is configured with two groups.
              <br><br>
              The master group is configured to run a control against the master VM by using the master_address output for the value of hostnames.
              <br><br>
              The workers group is configured to run a control against all of the worker VMs by using the workers_addresses output for the value of hostnames.
              <br><br>
              The platforms provide arbitrary grouping for the test suite matrix.
              <br><br>
              The suite name corresponds to the directory containing the Inspec profile: <div class="highlight"><pre class="syntax-highlight shell"><code><span class="nb">test</span>/integration/example/</code></pre></div>
            </div>
          </div>
        </div>
        <div class="tab-pane fade" id="list-two" role="tabpanel" aria-labelledby="list-two-list">
          Example Terraform code using the OpenStack provider is below. The resources created by this code is what we'll be testing later on.
          <br><br>
          Create this file <p class="font-weight-bold" style="color: #32c850; display: inline;">main.tf</p> and add each block of code into it.
          <br><br>
          The configuration is restricted to Terraform versions equal to or greater than 0.10.2 and less than 0.11.0.
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">terraform</span> <span class="p">{</span>
  <span class="n">required_version</span> <span class="o">=</span> <span class="s2">"~&gt; 0.10.2"</span>
<span class="p">}</span>
</code></pre></div>          Enable OpenStack provider to pass in OpenStack information and user authentication.
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">provider</span> <span class="s2">"openstack"</span> <span class="p">{</span>
  <span class="n">auth_url</span>    <span class="o">=</span> <span class="s2">"${var.provider_auth_url}"</span>
  <span class="n">password</span>    <span class="o">=</span> <span class="s2">"${var.provider_password}"</span>
  <span class="n">region</span>      <span class="o">=</span> <span class="s2">"${var.provider_region}"</span>
  <span class="n">tenant_name</span> <span class="o">=</span> <span class="s2">"${var.provider_tenant_name}"</span>
  <span class="n">user_name</span>   <span class="o">=</span> <span class="s2">"${var.provider_user_name}"</span>
<span class="p">}</span>
</code></pre></div>          Creates a SSH keypair, IP address and Ubuntu server which will act as a master server.
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">resource</span> <span class="s2">"openstack_compute_keypair_v2"</span> <span class="s2">"kitchen-terraform"</span> <span class="p">{</span>
  <span class="nb">name</span>       <span class="o">=</span> <span class="s2">"kitchen-terraform-example"</span>
  <span class="n">public_key</span> <span class="o">=</span> <span class="s2">"${file("</span><span class="p">.</span><span class="nf">/</span><span class="n">dummy_keypair</span><span class="o">/</span><span class="n">cloud</span><span class="p">.</span><span class="nf">key</span><span class="p">.</span><span class="nf">pub</span><span class="s2">")}"</span>
<span class="p">}</span>

<span class="n">resource</span> <span class="s2">"openstack_networking_floatingip_v2"</span> <span class="s2">"master"</span> <span class="p">{</span>
  <span class="n">pool</span> <span class="o">=</span> <span class="s2">"${var.networking_floatingips_pool}"</span>
<span class="p">}</span>

<span class="n">resource</span> <span class="s2">"openstack_compute_instance_v2"</span> <span class="s2">"master"</span> <span class="p">{</span>
  <span class="n">flavor_name</span> <span class="o">=</span> <span class="s2">"v.c1.m1024.d5.e0"</span>
  <span class="n">floating_ip</span> <span class="o">=</span> <span class="s2">"${element(openstack_networking_floatingip_v2.master.*.address, 0)}"</span>
  <span class="n">image_name</span>  <span class="o">=</span> <span class="s2">"ubuntu-16.04"</span>
  <span class="n">key_pair</span>    <span class="o">=</span> <span class="s2">"${openstack_compute_keypair_v2.kitchen-terraform.name}"</span>
  <span class="nb">name</span>        <span class="o">=</span> <span class="s2">"kitchen-terraform-example-master"</span>

  <span class="n">connection</span> <span class="p">{</span>
    <span class="n">host</span>        <span class="o">=</span> <span class="s2">"${self.floating_ip}"</span>
    <span class="n">private_key</span> <span class="o">=</span> <span class="s2">"${file("</span><span class="p">.</span><span class="nf">/</span><span class="n">dummy</span><span class="o">/</span><span class="n">cloud</span><span class="p">.</span><span class="nf">key</span><span class="s2">")}"</span>
    <span class="n">type</span>        <span class="o">=</span> <span class="s2">"ssh"</span>
    <span class="n">user</span>        <span class="o">=</span> <span class="s2">"ubuntu"</span>
  <span class="p">}</span>

  <span class="n">metadata</span> <span class="o">=</span> <span class="p">{</span>
    <span class="n">ssh_user</span> <span class="o">=</span> <span class="s2">"ubuntu"</span>
  <span class="p">}</span>

  <span class="n">network</span> <span class="p">{</span>
    <span class="nb">name</span> <span class="o">=</span> <span class="s2">"${var.compute_instances_network_name}"</span>
  <span class="p">}</span>

  <span class="n">provisioner</span> <span class="s2">"remote-exec"</span> <span class="p">{</span>
    <span class="n">inline</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"sudo apt-get install --no-install-recommends --yes nano"</span><span class="p">]</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div>          Uses the SSH key from above, creates a new IP address and Ubuntu server which will act as a worker server.
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">resource</span> <span class="s2">"openstack_networking_floatingip_v2"</span> <span class="s2">"workers"</span> <span class="p">{</span>
  <span class="n">count</span> <span class="o">=</span> <span class="mi">2</span>
  <span class="n">pool</span>  <span class="o">=</span> <span class="s2">"${var.networking_floatingips_pool}"</span>
<span class="p">}</span>

<span class="n">resource</span> <span class="s2">"openstack_compute_instance_v2"</span> <span class="s2">"worker"</span> <span class="p">{</span>
  <span class="n">count</span>       <span class="o">=</span> <span class="mi">2</span>
  <span class="n">flavor_name</span> <span class="o">=</span> <span class="s2">"v.c1.m1024.d5.e0"</span>
  <span class="n">floating_ip</span> <span class="o">=</span> <span class="s2">"${element(openstack_networking_floatingip_v2.workers.*.address, count.index)}"</span>
  <span class="n">image_name</span>  <span class="o">=</span> <span class="s2">"ubuntu-16.04"</span>
  <span class="n">key_pair</span>    <span class="o">=</span> <span class="s2">"${openstack_compute_keypair_v2.kitchen-terraform.name}"</span>
  <span class="nb">name</span>        <span class="o">=</span> <span class="s2">"kitchen-terraform-example-worker-${count.index+1}"</span>

  <span class="n">connection</span> <span class="p">{</span>
    <span class="n">host</span>        <span class="o">=</span> <span class="s2">"${self.floating_ip}"</span>
    <span class="n">private_key</span> <span class="o">=</span> <span class="s2">"${file("</span><span class="p">.</span><span class="nf">/</span><span class="n">dummy</span><span class="o">/</span><span class="n">cloud</span><span class="p">.</span><span class="nf">key</span><span class="s2">")}"</span>
    <span class="n">type</span>        <span class="o">=</span> <span class="s2">"ssh"</span>
    <span class="n">user</span>        <span class="o">=</span> <span class="s2">"ubuntu"</span>
  <span class="p">}</span>

  <span class="n">metadata</span> <span class="o">=</span> <span class="p">{</span>
    <span class="n">ssh_user</span> <span class="o">=</span> <span class="s2">"ubuntu"</span>
  <span class="p">}</span>

  <span class="n">network</span> <span class="p">{</span>
    <span class="nb">name</span> <span class="o">=</span> <span class="s2">"${var.compute_instances_network_name}"</span>
  <span class="p">}</span>

  <span class="n">provisioner</span> <span class="s2">"remote-exec"</span> <span class="p">{</span>
    <span class="n">inline</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"sudo apt-get install --no-install-recommends --yes curl"</span><span class="p">]</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div>        </div>
        <div class="tab-pane fade" id="list-three" role="tabpanel" aria-labelledby="list-three-list">
          We also need to setup variables as some networking and provider attributes are required to make the Terraform code work successfully.
          <br><br>
          Create this file <p class="font-weight-bold" style="color: #32c850; display: inline;">variable.tf</p> and add the below block of code into it.
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">variable</span> <span class="s2">"compute_instances_network_name"</span> <span class="p">{</span>
  <span class="n">description</span> <span class="o">=</span> <span class="s2">"The human-readable name of the network of the compute instances"</span>
  <span class="n">type</span>        <span class="o">=</span> <span class="s2">"string"</span>
<span class="p">}</span>

<span class="n">variable</span> <span class="s2">"networking_floatingips_pool"</span> <span class="p">{</span>
  <span class="n">description</span> <span class="o">=</span> <span class="s2">"The name of the pool from which to obtain the floating IP addresses"</span>
  <span class="n">type</span>        <span class="o">=</span> <span class="s2">"string"</span>
<span class="p">}</span>

<span class="n">variable</span> <span class="s2">"provider_auth_url"</span> <span class="p">{</span>
  <span class="n">description</span> <span class="o">=</span> <span class="s2">"The identity authentication URL"</span>
  <span class="n">type</span>        <span class="o">=</span> <span class="s2">"string"</span>
<span class="p">}</span>

<span class="n">variable</span> <span class="s2">"provider_password"</span> <span class="p">{</span>
  <span class="n">description</span> <span class="o">=</span> <span class="s2">"The password to login with"</span>
  <span class="n">type</span>        <span class="o">=</span> <span class="s2">"string"</span>
<span class="p">}</span>

<span class="n">variable</span> <span class="s2">"provider_region"</span> <span class="p">{</span>
  <span class="n">description</span> <span class="o">=</span> <span class="s2">"The cloud region to use"</span>
  <span class="n">type</span>        <span class="o">=</span> <span class="s2">"string"</span>
<span class="p">}</span>

<span class="n">variable</span> <span class="s2">"provider_tenant_name"</span> <span class="p">{</span>
  <span class="n">description</span> <span class="o">=</span> <span class="s2">"The name of the tenant to login with"</span>
  <span class="n">type</span>        <span class="o">=</span> <span class="s2">"string"</span>
<span class="p">}</span>

<span class="n">variable</span> <span class="s2">"provider_user_name"</span> <span class="p">{</span>
  <span class="n">description</span> <span class="o">=</span> <span class="s2">"The user ID to login with"</span>
  <span class="n">type</span>        <span class="o">=</span> <span class="s2">"string"</span>
<span class="p">}</span>
</code></pre></div>        </div>
        <div class="tab-pane fade" id="list-four" role="tabpanel" aria-labelledby="list-four-list">
          To assist in testing, Terraform outputs will provide the master and worker server addresses. The Kitchen-Terraform verifier can use these artifacts to validate the Terraform code.
          <br><br>
          Create this file <p class="font-weight-bold" style="color: #32c850; display: inline;">output.tf</p> and add each block of code into it.
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">output</span> <span class="s2">"master_address"</span> <span class="p">{</span>
  <span class="n">value</span> <span class="o">=</span> <span class="s2">"${openstack_networking_floatingip_v2.master.address}"</span>
<span class="p">}</span>

<span class="n">output</span> <span class="s2">"workers_addresses"</span> <span class="p">{</span>
  <span class="n">value</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"${openstack_networking_floatingip_v2.workers.*.address}"</span><span class="p">]</span>
<span class="p">}</span>
</code></pre></div>          Refer back to the .kitchen.yml and in the verifier section you will see a reference to the above hostnames output.
        </div>
        <div class="tab-pane fade" id="list-five" role="tabpanel" aria-labelledby="list-five-list">
          Before creating the tests, let's setup our OpenStack provider information. This helps get the URL, user authentication and a couple other provider specific items setup.
          <br><br>
          Create this file <p class="font-weight-bold" style="color: #32c850; display: inline;">my-variables.tfvars</p> and add the block of code into it.
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="n">compute_instances_network_name</span> <span class="o">=</span> <span class="s2">"&lt;VALUE&gt;"</span>
<span class="n">networking_floatingips_pool</span>    <span class="o">=</span> <span class="s2">"&lt;VALUE&gt;"</span>
<span class="n">provider_auth_url</span>              <span class="o">=</span> <span class="s2">"&lt;VALUE&gt;"</span>
<span class="n">provider_password</span>              <span class="o">=</span> <span class="s2">"&lt;VALUE&gt;"</span>
<span class="n">provider_region</span>                <span class="o">=</span> <span class="s2">"&lt;VALUE&gt;"</span>
<span class="n">provider_tenant_name</span>           <span class="o">=</span> <span class="s2">"&lt;VALUE&gt;"</span>
<span class="n">provider_user_name</span>             <span class="o">=</span> <span class="s2">"&lt;VALUE&gt;"</span>
</code></pre></div>          Refer back to the .kitchen.yml and in the driver section you will see a reference to the above my-variables.tfvars file.
        </div>
        <div class="tab-pane fade" id="list-six" role="tabpanel" aria-labelledby="list-six-list">
          We've created the Terraform code, now it's time to create the Inspec control tests. Please see the <a href="https://www.inspec.io/docs/reference/profiles/" style="color: #32c850;">Inspec documentation</a> to learn more about profiles and controls.
          <br><br>
          Create a default profile file <p class="font-weight-bold" style="color: #32c850; display: inline;">test/integration/example/inspec.yml</p>
          <br><br>
<div class="highlight"><pre class="syntax-highlight yaml"><code><span class="nn">---</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">default</span>
</code></pre></div>          Referring back to the .kitchen.yml file and inside the verifier section there is a nano_installed control which we need to create.
          <br><br>
          Create this file <p class="font-weight-bold" style="color: #32c850; display: inline;">test/integration/example/controls/nano_installed_spec.rb</p>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="c1"># frozen_string_literal: true</span>

<span class="n">control</span> <span class="s2">"nano_installed"</span> <span class="k">do</span>
  <span class="n">describe</span> <span class="n">package</span> <span class="s2">"nano"</span> <span class="k">do</span>
    <span class="n">it</span> <span class="k">do</span>
      <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">be_installed</span>
    <span class="k">end</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div>          Let's create the curl_installed control, which will validate curl is installed.
          <br><br>
          Create this file <p class="font-weight-bold" style="color: #32c850; display: inline;">test/integration/example/controls/curl_installed_spec.rb</p>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="c1"># frozen_string_literal: true</span>

<span class="n">control</span> <span class="s2">"curl_installed"</span> <span class="k">do</span>
  <span class="n">describe</span> <span class="n">package</span> <span class="s2">"curl"</span> <span class="k">do</span>
    <span class="n">it</span> <span class="k">do</span>
      <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">be_installed</span>
    <span class="k">end</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div>        </div>
        <div class="tab-pane fade" id="list-seven" role="tabpanel" aria-labelledby="list-seven-list">
          Execute Kitchen-Terraform by running these commands
          <br><br>
<div class="highlight"><pre class="syntax-highlight ruby"><code><span class="c1"># Create resources from the Terraform code in main.tf</span>
<span class="n">bundle</span> <span class="nb">exec</span> <span class="n">kitchen</span> <span class="n">converge</span>

<span class="c1"># Run the Inspec controls from the .kitchen.yml verifier section</span>
<span class="n">bundle</span> <span class="nb">exec</span> <span class="n">kitchen</span> <span class="n">verify</span>
</code></pre></div>        </div>
      </div>
    </div>
  </div>
</div>

    </div>
    <footer class="footer">
      <div class="container">
        <span class="text-muted">Community driven, created and maintained by
          <a href="http://copado.com" style="color: #32c850;">
            <img src="/kitchen-terraform/images/copado_logo.png" class="d-inline-block" style="vertical-align: sub;" width="30" height="24" alt="Copado NCS LLC logo" />
            Copado NCS LLC
          </a>
        </span>
      </div>
    </footer>
  </body>
</html>
